package org.jeecg.modules.app.v1.config.contoller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.power.config.entity.YlConfig;
import org.jeecg.modules.power.config.entity.YlProtocol;
import org.jeecg.modules.power.config.entity.YlQuestion;
import org.jeecg.modules.power.config.service.IYlConfigService;
import org.jeecg.modules.power.config.service.IYlProtocolService;
import org.jeecg.modules.power.config.service.IYlQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @Description: 系统参数配置
* @Author: jeecg-boot
* @Date:   2024-07-02
* @Version: V1.0
*/
@Api(tags="系统参数配置")
@RestController
@RequestMapping("/api/v1/ylConfig")
@Slf4j
@RequiredArgsConstructor
public class ApiConfigController {

    /**
     * 系统参数配置
     */
    private final IYlConfigService ylConfigService;
    /**
     * 系统协议
     */
    private final IYlProtocolService ylProtocolService;
    /**
     * 智能问答
     */
    private final IYlQuestionService ylQuestionService;
   /**
    * 通过id查询
    * @return
    */
   @ApiOperation(value="系统参数配置", notes="系统参数配置")
   @GetMapping(value = "/config")
   public Result<YlConfig> config() {
       QueryWrapper queryWrapper = new QueryWrapper();
       queryWrapper.last("limit 1");
       YlConfig ylConfig = ylConfigService.getOne(queryWrapper);
       if(ylConfig==null) {
           return Result.error_599("未配置");
       }
       return Result.OK(ylConfig);
   }

    @ApiOperation(value="获取各种协议", notes="获取各种协议")
    @GetMapping(value = "/protocol")
    public Result<YlProtocol> getProtocol() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.last("limit 1");
        YlProtocol ylProtocol = ylProtocolService.getOne(queryWrapper);
        if(ylProtocol==null) {
            return Result.error_599("未配置");
        }
        return Result.OK(ylProtocol);
    }

    @ApiOperation(value="客服中心问答", notes="客服中心问答")
    @GetMapping(value = "/list")
    public Result<Map<String,List<Map<String,Object>>>> queryPageList(Integer type) {
        return Result.OK(ylQuestionService.getQuestionList(type));
    }


}
